import 'package:get/get.dart';
import 'dart:async';

import '../../config/router_page_name.dart';
import '../../services/auth_service.dart';

class SplashLogic extends GetxController {
  final AuthService _authService = AuthService();

  @override
  void onInit() {
    super.onInit();
    _initApp();
  }

  Future<void> _initApp() async {
    // Simulate splash screen delay
    await Future.delayed(const Duration(seconds: 2));

    // Check if user is logged in
    bool isLoggedIn = await _authService.isLoggedIn();

    if (isLoggedIn) {
      Get.offAllNamed(RouterPageName.mainPage);
    } else {
      Get.offAllNamed(RouterPageName.loginPage);
    }
  }
}
